{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-09-06T03:05:42.613206Z",
     "start_time": "2020-09-06T03:05:42.609217Z"
    }
   },
   "source": [
    "**只打印或显示numpy数组rand_arr的小数点后3位。**\n",
    "\n",
    "- `rand_arr = np.random.random([5, 3])`\n",
    "\n",
    "【知识点：输入和输出】\n",
    "- 如何在numpy数组中只打印小数点后三位？"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-09-06T03:06:03.840763Z",
     "start_time": "2020-09-06T03:06:03.834778Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[0.25106063 0.32735642 0.17623774]\n",
      " [0.85566173 0.11420437 0.53735783]\n",
      " [0.82253612 0.07625331 0.9358199 ]\n",
      " [0.97268875 0.91794448 0.61845404]\n",
      " [0.58615827 0.28096349 0.88048956]]\n",
      "[[0.251 0.327 0.176]\n",
      " [0.856 0.114 0.537]\n",
      " [0.823 0.076 0.936]\n",
      " [0.973 0.918 0.618]\n",
      " [0.586 0.281 0.88 ]]\n"
     ]
    }
   ],
   "source": [
    "import numpy as np\n",
    "\n",
    "rand_arr = np.random.random([5, 3])\n",
    "print(rand_arr)\n",
    "# [[0.33033427 0.05538836 0.05947305]\n",
    "#  [0.36199439 0.48844555 0.26309599]\n",
    "#  [0.05361816 0.71539075 0.60645637]\n",
    "#  [0.95000384 0.31424729 0.41032467]\n",
    "#  [0.36082793 0.50101268 0.6306832 ]]\n",
    "\n",
    "np.set_printoptions(precision=3)\n",
    "print(rand_arr)\n",
    "# [[0.33  0.055 0.059]\n",
    "#  [0.362 0.488 0.263]\n",
    "#  [0.054 0.715 0.606]\n",
    "#  [0.95  0.314 0.41 ]\n",
    "#  [0.361 0.501 0.631]]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-09-06T03:06:22.855956Z",
     "start_time": "2020-09-06T03:06:22.850970Z"
    }
   },
   "source": [
    "**将numpy数组a中打印的项数限制为最多6个元素。**\n",
    "\n",
    "【知识点：输入和输出】\n",
    "- 如何限制numpy数组输出中打印的项目数？"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-09-06T03:06:51.128200Z",
     "start_time": "2020-09-06T03:06:51.123215Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[ 0  1  2  3  4  5  6  7  8  9 10 11 12 13 14]\n",
      "[ 0  1  2 ... 12 13 14]\n"
     ]
    }
   ],
   "source": [
    "import numpy as np\n",
    "\n",
    "a = np.arange(15)\n",
    "print(a)\n",
    "# [ 0  1  2  3  4  5  6  7  8  9 10 11 12 13 14]\n",
    "np.set_printoptions(threshold=6)\n",
    "print(a)\n",
    "# [ 0  1  2 ... 12 13 14]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-09-06T03:07:14.131621Z",
     "start_time": "2020-09-06T03:07:14.126608Z"
    }
   },
   "source": [
    "**打印完整的numpy数组a而不中断。**\n",
    "\n",
    "【知识点：输入和输出】\n",
    "- 如何打印完整的numpy数组而不中断？"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-09-06T03:07:47.868079Z",
     "start_time": "2020-09-06T03:07:47.863126Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[ 0  1  2 ... 12 13 14]\n",
      "[ 0  1  2  3  4  5  6  7  8  9 10 11 12 13 14]\n"
     ]
    }
   ],
   "source": [
    "import numpy as np\n",
    "\n",
    "a = np.arange(15)\n",
    "np.set_printoptions(threshold=6)\n",
    "print(a)\n",
    "# [ 0  1  2 ... 12 13 14]\n",
    "np.set_printoptions(threshold=np.iinfo(np.int).max)\n",
    "print(a)\n",
    "# [ 0  1  2  3  4  5  6  7  8  9 10 11 12 13 14]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python35",
   "language": "python",
   "name": "python35"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.10"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  },
  "varInspector": {
   "cols": {
    "lenName": 16,
    "lenType": 16,
    "lenVar": 40
   },
   "kernels_config": {
    "python": {
     "delete_cmd_postfix": "",
     "delete_cmd_prefix": "del ",
     "library": "var_list.py",
     "varRefreshCmd": "print(var_dic_list())"
    },
    "r": {
     "delete_cmd_postfix": ") ",
     "delete_cmd_prefix": "rm(",
     "library": "var_list.r",
     "varRefreshCmd": "cat(var_dic_list()) "
    }
   },
   "types_to_exclude": [
    "module",
    "function",
    "builtin_function_or_method",
    "instance",
    "_Feature"
   ],
   "window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
